import sys
import asyncio
import asyncio.streams

@asyncio.coroutine
def client(name):
    reader, writer = yield from asyncio.streams.open_connection(
        '127.0.0.1', 12345, loop=loop)
    def send(msg):
        writer.write((msg + '\r\n').encode("utf-8"))

    send('Auth:: %s' % name)
    try:
        while True:
            yield from asyncio.sleep(2)
            send('Baz:: Bar')
            send('Cat:: tail')
            send('Juk:: filosof')
    finally:
        writer.close()

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    msg = loop.run_until_complete(client(sys.argv[1]))



